#include"util.hpp"
#include"data.hpp"
#include"server.hpp"

void FileTest1()
{
    aod::FileUtil("./www").CreateDirectory();
    aod::FileUtil("./www/index.html").WriteContent("<html></html>");
    std::string body;
    aod::FileUtil("./www/index.html").ReadContent(&body);
    std::cout << body << std::endl;
    std::cout << aod::FileUtil("./www/index.html").Size() <<std::endl;
}

void JsonTest1()
{
    Json::Value val;
    val["Name"] = "Gavin";
    val["Sex"] = "man";
    val["Age"] = 21;
    val["Score"].append(110.5);   
    val["Score"].append(110.5);   
    val["Score"].append(120.5);

    std::string body;
    aod::JsonUtil::Serialize(val, &body);
    std::cout << body <<std::endl;

    Json::Value stu;
    aod::JsonUtil::Unserialize(body, &stu);
    std::cout << stu["Name"].asString() <<std::endl;   
    std::cout << stu["Sex"].asString() <<std::endl;   
    std::cout << stu["Age"].asString() <<std::endl;
    for(auto &a : stu["Score"])
    {
        std::cout << a.asFloat() <<std::endl;
    }   
}

void DataTest()
{
    aod::TableVideo tb_video;
    Json::Value video;
    video["name"] = "Jhon";
    video["info"] = "a man but not a student";
    video["video"] = "/video/man.ma4";
    video["image"] = "/image/man.jpg";
    tb_video.Insert(video);
    // tb_video.Update(2, video);
    // tb_video.SelectAll(&video);
    // tb_video.SelectOne(1, &video);
    // tb_video.SelectLike("Gavin", &video);
    // std::string body;
    // aod::JsonUtil::Serialize(video, &body);
    // std::cout << body <<std::endl;
    // tb_video.Delete(2);
}

void ServerTest()
{
    aod::Server server(8888);
    server.RunModule();
}

int main()
{
    //FileTest1();
    //JsonTest1();
    //DataTest();
    ServerTest();
    return 0;
}